package Thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-08-03
 * Time: 21:49
 */
public class demo19 {
    private static Object locker = new Object();

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            synchronized (locker) {
                System.out.println("t1 wait之前");
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("t1 wait之后");
        });
        Thread t2 = new Thread(() -> {
            System.out.println("t2 notify之前");
            synchronized (locker) {
                locker.notify();//wait和notify是同一个对象,才能生效,notify也是要加锁的~
            }
            System.out.println("t2 notify之后");
        });
        t1.start();
        t2.start();
    }
}
